package pages 
{
	import com.gaiaframework.api.Gaia;
	import com.gaiaframework.api.IStyleSheet;
	import com.gaiaframework.templates.AbstractPage;
	import com.google.analytics.AnalyticsTracker;
	import com.google.analytics.GATracker;
	import com.greensock.easing.Quint;
	import com.greensock.TweenLite;
	import flash.events.MouseEvent;
	import model.Model;
	import ui.media.Diaporama;
	import utils.TextFieldUtil;
	
	/**
	 * ...
	 * @author usual
	 */
	public class VideosPage extends AbstractPage 
	{
		private var _diaporama:Diaporama;
		private var _sens:String = "v";
		private var _tracker:AnalyticsTracker;
		public function VideosPage() 
		{
			super();
		}
		override public function transitionIn():void 
		{
			super.transitionIn();
			TextFieldUtil.setStyle(IStyleSheet(Gaia.api.getPage(Pages.INDEX).assets.styles).style);
			_diaporama = new Diaporama(_sens,this.page.branch);
			addChild(_diaporama);
			addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveEvent);
			transitionInComplete();
			_tracker = new GATracker(this, Model.instance.getGa(), "AS3", false);
			_tracker.trackPageview('/videos');
		}
		
		private function mouseMoveEvent(e:MouseEvent):void 
		{
			var sP:Number;
			if (_sens == "h")
			{
				var xR:Number = _diaporama.width - stage.stageWidth;
				sP = e.stageX / stage.stageWidth;
				var rX:Number = xR * sP;			
				TweenLite.to(_diaporama, 3, { x: -rX, ease:Quint.easeOut } );
			}
			if (_sens == 'v')
			{
				var yR:Number = _diaporama.height - stage.stageHeight;
				sP = e.stageY / stage.stageHeight;	
				var rY:Number = yR * sP;
				TweenLite.to(_diaporama, 3, { y: -rY, ease:Quint.easeOut } );
			}
		}
		override public function transitionOut():void 
		{
			super.transitionOut();
			
			_diaporama.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveEvent);
			_diaporama.destroy();
			transitionOutComplete();
		}
	}

}